package com.digitalchina.lxnsy.activity.mainConsult;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.entity.ConsultRefundApplyVO;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.JointImageUrl;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;
import com.lzy.okhttputils.model.HttpParams;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ApplyRefundDetailActivity extends BaseActivity {


    @Bind(R.id.tv_auditStatus)
    TextView tvAuditStatus;
    @Bind(R.id.tv_auditOpinion)
    TextView tvAuditOpinion;
    @Bind(R.id.tv_reason)
    TextView tvReason;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.nineGrid_rep)
    NineGridView nineGridRep;
    private String consultRefundApplyId = "";

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_refund_detail);
        setTitle("退款详情");
    }

    @Override
    public void initMember() {
        consultRefundApplyId = (String) getIntent().getSerializableExtra("consultRefundApplyId");
        consultApplyRefundDetail();
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                switch (msg.what) {
                    case MSG_S_0:
                        callBack(msg.obj);
                        break;
                    case MSG_F_0:
                        showToast(msg.obj.toString());
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public void callBack(Object object) {
        ConsultRefundApplyVO vo = FastJsonUtil.getBean(object.toString(), "consultRefundApply", ConsultRefundApplyVO.class);

        if (vo == null) {
            showToast("获取失败");
            return;
        }

        //审核状态 0 待审核 1 审核通过 2 审核驳回
        switch (vo.getAuditStatus()) {
            case 0:
                tvAuditStatus.setText("审核状态：待审核");
                break;
            case 1:
                tvAuditStatus.setText("审核状态：审核通过");
                break;
            case 2:
                tvAuditStatus.setText("审核状态：审核驳回");
                break;
        }

        if (!StringUtil.isStrEmpty(vo.getAuditOpinion())) {
            tvAuditOpinion.setText("审核意见：" + vo.getAuditOpinion());
        }


        tvReason.setText("退款原因：" + vo.getRefundReason());

        tvTime.setText(vo.getCreateTime());


        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        if (vo.getPictureList() != null && vo.getPictureList().size() > 0) {
            nineGridRep.setVisibility(View.VISIBLE);
            for (int i = 0; i < vo.getPictureList().size(); i++) {
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(JointImageUrl.smallImageUrl(vo.getPictureList().get(i).getPictureVideoId()));
                info.setBigImageUrl(JointImageUrl.bigImageUrl(vo.getPictureList().get(i).getPictureVideoId()));
                imageInfo.add(info);
            }
            nineGridRep.setAdapter(new NineGridViewClickAdapter(this, imageInfo));
        }
    }

    @Override
    public void rightOnClick() {

    }

    private void consultApplyRefundDetail() {


        HttpParams params = new HttpParams();
        params.put("consultRefundApplyId", consultRefundApplyId);

        OkHttpUtil.post(activity, URL.URL_CONSULT_APPLY_REFUND_DETAIL, "查询中...", params, mHandler,
                MSG_S_0, MSG_F_0);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
